//
//  WHCoopRequestInfoCell.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/6.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHCoopRequestInfoCell.h"

@interface WHCoopRequestInfoCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UIButton *acceptBtn;
@property (nonatomic, strong) UIButton *refuseBtn;

@end

@implementation WHCoopRequestInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = CViewBgMainColor;
        [self setMoneyDetailInfoUI];
    }
    return self;
}

- (void)setMoneyDetailInfoUI {
    [self.contentView addSubview:({
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.adjustsFontSizeToFitWidth = YES;
        _nameLabel.textColor = CFontContentGrayColor;
        _nameLabel.font = SYSTEMFONT(kRealwidth(15));
        
        ViewBorderRadius(_nameLabel, 0, 0.5, CLineColor);
        
        _nameLabel;
    })];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.mas_equalTo(self.contentView);
        make.width.mas_equalTo(kRealwidth(120));
    }];
    
    [self.contentView addSubview:({
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
        _moneyLabel.adjustsFontSizeToFitWidth = YES;
        _moneyLabel.textColor = CFontContentGrayColor;
        _moneyLabel.font = SYSTEMFONT(kRealwidth(15));
        
        ViewBorderRadius(_moneyLabel, 0, 0.5, CLineColor);
        
        _moneyLabel;
    })];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(_nameLabel.mas_right);
        make.width.mas_equalTo(kRealwidth(125));
    }];
    
    [self.contentView addSubview:({
        _statusLabel = [[UILabel alloc] init];
        _statusLabel.textAlignment = NSTextAlignmentCenter;
        _statusLabel.adjustsFontSizeToFitWidth = YES;
        _statusLabel.textColor = CMDarkOrangeColor;
        _statusLabel.font = SYSTEMFONT(kRealwidth(15));
//        _statusLabel.text = @"通过/拒绝";
        _statusLabel.userInteractionEnabled = YES;
        
        ViewBorderRadius(_statusLabel, 0, 0.5, CLineColor);
        
        _statusLabel;
    })];
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(_moneyLabel.mas_right);
        make.width.mas_equalTo(kRealwidth(130));
    }];
    
    [_statusLabel addSubview:({
        _acceptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *acceptTitle = @"通过";
        NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:acceptTitle attributes:@{NSFontAttributeName:SYSTEMFONT(kRealwidth(12)), NSForegroundColorAttributeName:CMDarkOrangeColor}];
        [_acceptBtn setAttributedTitle:attributeStr forState:UIControlStateNormal];
        ViewBorderRadius(_acceptBtn, kRealwidth(22)/2, 1, CMDarkOrangeColor);
        [_acceptBtn addTarget:self action:@selector(accept:) forControlEvents:UIControlEventTouchUpInside];
        _acceptBtn;
    })];
    [_acceptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_statusLabel.mas_left).offset(kRealwidth(10));
        make.centerY.mas_equalTo(_statusLabel.mas_centerY);
        make.height.mas_equalTo(kRealwidth(22));
        make.width.mas_equalTo(kRealwidth(50));
    }];
    
    [_statusLabel addSubview:({
        _refuseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *refuseTitle = @"拒绝";
        NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:refuseTitle attributes:@{NSFontAttributeName:SYSTEMFONT(kRealwidth(12)), NSForegroundColorAttributeName:CMDarkOrangeColor}];
        [_refuseBtn setAttributedTitle:attributeStr forState:UIControlStateNormal];
        ViewBorderRadius(_refuseBtn, kRealwidth(22)/2, 1, CMDarkOrangeColor);
        
        [_refuseBtn addTarget:self action:@selector(refuse:) forControlEvents:UIControlEventTouchUpInside];
        _refuseBtn;
    })];
    [_refuseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_statusLabel.mas_right).offset(-kRealwidth(10));
        make.centerY.mas_equalTo(_statusLabel.mas_centerY);
        make.height.mas_equalTo(kRealwidth(22));
        make.width.mas_equalTo(kRealwidth(50));
    }];
    
}

- (void)accept:(UIButton *)button {
    if (self.updateStatus) {
        self.updateStatus(1);
    }
}

- (void)refuse:(UIButton *)button {
    if (self.updateStatus) {
        self.updateStatus(2);
    }
}

- (void)setNameModel:(WHStationNameModel *)nameModel {
    _nameModel = nameModel;
    
    _nameLabel.text = NSStringFormat(@"  %@  ", nameModel.nickName);
    _moneyLabel.text = nameModel.saveMoney;
}

@end
